package game.games.rpg;

import game.gfx.ColoredChar;
import game.gfx.ConsoleColor;

import java.util.Random;

public class FancyMonster extends Monster
{
    private int            index;
    private ColoredChar[]  bodys;
    private boolean        random;
    // blink rate
    private double         bps = 2.0;
    private long           lastBlink;

    public FancyMonster(ColoredChar[] bodys, int health, int attack, boolean random)
    {
        super(' ', ConsoleColor.DEFAULT, health, attack);
        this.index = 0;
        this.bodys = bodys;
        this.random = random;
    }

    private void checkNext()
    {
        // next?
        long current = System.currentTimeMillis();
        long diff = current - lastBlink;
        if (diff > (1000 / bps))
        {
            lastBlink = current;
            if (bodys != null && bodys.length > 0)
            {
                if (random)
                {
                    index = new Random().nextInt(bodys.length);
                }
                else
                {
                    index++;
                    // over the line?
                    if (index >= bodys.length)
                    {
                        index = 0;
                    }
                }
            }
        }
    }
    
    public ColoredChar[] getBodys()
    {
        return bodys;
    }
    
    public void setBodys(ColoredChar[] bodys)
    {
        this.bodys = bodys;
    }
    
    @Override
    public ColoredChar getChar()
    {
        checkNext();
        return bodys[index].clone();
    }
}
